// bien toan cuc

var canvas;
var board;

function drawText(ctx, content, size, x, y) {
    // Set font
    ctx.font = size + "px Old English Text MT";
    // draw
    ctx.fillStyle = "black";
    ctx.fillText(content, x, y);
}

function Load() {
    soundManager.s_background.play();
    m_gameState = true;
    canvas = document.getElementById("canvas");
    canvas.style.position = "absolute";
    context = canvas.getContext("2d");
    board = new Board();
    board.SetBoard(ConstValue.pixDir() + "ixiangqi.png");
    board.InitializeChessPiece();
    board.Draw();

   
    canvas.addEventListener("mousedown", OnClickBoard, false);
}

function OnClickBoard(e)
{
    var pos = getMousePos(e);

    board.Click(pos);
    context.clearRect(0, 0, 480, 800);
    board.Draw();
}

function getMousePos(e)
{
    var pos = new Point(0, 0);
    pos.SetX(getMouseY(e));
    pos.SetY(getMouseX(e));

    return pos;
}

function getMouseX(e) {
    // Play button
    var canvasX;
    var mousePageX;
    var mouseCanvasX;

    //Lay toa do cua canvas
    canvasX = canvas.offsetLeft;

    //Lay toa do cua chuot
    mousePageX = e.pageX;

    //Lay toa do cua chuot tren canvas
    mouseCanvasX = mousePageX - canvasX;

    return mouseCanvasX;
}

function getMouseY(e) {
    // Play button
    var canvasY;
    var mousePageY;
    var mouseCanvasY;

    //Lay toa do cua canvas
    canvasY = canvas.offsetTop;

    //Lay toa do cua chuot
    mousePageY = e.pageY;

    //Lay toa do cua chuot tren canvas
    mouseCanvasY = mousePageY - canvasY;

    return mouseCanvasY;
}